package com.wx.redis.mq;

import cn.hutool.core.lang.UUID;
import com.google.gson.Gson;
import jakarta.annotation.Resource;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

/**
 * @author weixin 2024/11/20 15:34
 */
@Service
public class SendMqService {

    @Resource
    private RedissonClient redissonClient;

    /**
     * 发送消息
     * @param bizEnum
     * @param param
     */
    public void send(BizEnum bizEnum, Object param){
        Gson gson = new Gson();

        MqMessageBo mqMessageBo = new MqMessageBo();
        mqMessageBo.setMqId(UUID.fastUUID().toString(true));
        mqMessageBo.setBody(gson.toJson(param));
        for (String topic : bizEnum.getTopicList()) {
            redissonClient.getTopic(topic).publish(gson.toJson(mqMessageBo));
        }

    }
}
